package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Message;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;
import com.hengxinguotong.zhihuichengjian.widget.view.CircleImageView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/4.
 */

public class MessageListAdapter extends BaseAdapter {

    private List<Message> messageList;
    private LayoutInflater inflater;

    public MessageListAdapter(List<Message> messageList, Context context) {
        this.messageList = messageList;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return messageList.size();
    }

    @Override
    public Object getItem(int position) {
        return messageList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(null == convertView || null == convertView.getTag()){
            convertView = inflater.inflate(R.layout.item_message, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();
        }
        Message message = messageList.get(position);
        switch (message.getType()){
            case 0:
                holder.item_icon.setImageResource(R.mipmap.xitongxiaoxi);
                holder.item_type.setText("系统消息");
                break;
            case 1:
                holder.item_icon.setImageResource(R.mipmap.icon_zhiliangzhenggai);
                holder.item_type.setText("质量整改");
                break;
            case 2:
                holder.item_icon.setImageResource(R.mipmap.icon_anquanzhenggai);
                holder.item_type.setText("安全整改");
                break;
            case 3:
                holder.item_icon.setImageResource(R.mipmap.icon_renwupaifa);
                holder.item_type.setText("任务派发");
                break;
            case 4:
                holder.item_icon.setImageResource(R.mipmap.icon_yuyuetadiao);
                holder.item_type.setText("预约塔吊");
                break;
            case 5:
                holder.item_icon.setImageResource(R.mipmap.icon_shengjiangji);
                holder.item_type.setText("预约升降机");
                break;
            case 6:
                holder.item_icon.setImageResource(R.mipmap.icon_gongchenjindu);
                holder.item_type.setText("工程进度");
                break;
            case 7:
                holder.item_icon.setImageResource(R.mipmap.icon_huanjingjianche);
                holder.item_type.setText("PM10预警");
                break;
            case 8:
                holder.item_icon.setImageResource(R.mipmap.icon_huanjingjianche);
                holder.item_type.setText("噪音预警");
                break;
            case 9:
                holder.item_icon.setImageResource(R.mipmap.icon_yuyuetadiao);
                holder.item_type.setText("塔吊预警");
                break;
            case 10:
                holder.item_icon.setImageResource(R.mipmap.icon_shengjiangji);
                holder.item_type.setText("升降机预警");
                break;
            case 11:
                holder.item_icon.setImageResource(R.mipmap.icon_huanjingjianche);
                holder.item_type.setText("PM2.5预警");
                break;
            case 12:
            case 13:
                holder.item_icon.setImageResource(R.mipmap.icon_zhiliangzhenggai);
                holder.item_type.setText("现场检查整改");
                break;
        }
        holder.item_type.setText(message.getTitle());
        holder.item_time.setText(message.getCreateTime());
        holder.item_title.setText(message.getContent());
        if(message.getIsRead() == 0){
            holder.red_point.setVisibility(View.VISIBLE);
        }else if(message.getIsRead() == 1){
            holder.red_point.setVisibility(View.INVISIBLE);
        }
        return convertView;
    }

    static class ViewHolder{
        @BindView(R.id.item_icon)
        ImageView item_icon;
        @BindView(R.id.red_point)
        CircleImageView red_point;
        @BindView(R.id.item_type)
        HXTextView item_type;
        @BindView(R.id.item_title)
        HXTextView item_title;
        @BindView(R.id.item_time)
        HXTextView item_time;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
